<?PHP

class Utils{
	function findImageUrlinHTML($html){	
 		if(preg_match('/<[Ii]{1}[mM]{1}[Gg]{1}/i',$html,$matches,PREG_OFFSET_CAPTURE)>0){
    		$offset=$matches[0][1];
    		$imgstring='';
    		$i=$offset+4;
    		while($html[$i]!='>'){
    				$imgstring.=$html[$i];
    				$i++;
    		}
    		
    		preg_match('/ +[Ss]{1}[Rr]{1}[Cc]{1}/i',$imgstring,$matches2,PREG_OFFSET_CAPTURE);
    		$offset2=$matches2[0][1];
    		$j=$offset2+3;
    		while(($imgstring[$j]!='"')&&($imgstring[$j]!="\'")) $j++;
    		$j++;
    		$url='';
    		while(($imgstring[$j]!='"')&&($imgstring[$j]!="\'")){
    			$url.=$imgstring[$j];
    			$j++;
    		}
    	/*	if(!strstr($url,'http://'))
    			$url.='http://'.$_SERVER['HTTP_HOST'];*/
    			if($url[0]=='/') $url=substr($url,1);
    		return $url;
 		}
    	return null;
	}
	
	function &createEmailArticle($html){
		$images=array();
		$off=0;
		while(preg_match('/<[Ii]{1}[mM]{1}[Gg]{1}/i',$html,$matches,PREG_OFFSET_CAPTURE,$off)>0){
				$offset=$matches[0][1];
				$imgstring='';
    			$i=$offset+4;
    			$off=$i;
    			while($html[$i]!='>'){
    				$imgstring.=$html[$i];
    				$i++;
    			}	
				preg_match('/ +[Ss]{1}[Rr]{1}[Cc]{1}/i',$imgstring,$matches2,PREG_OFFSET_CAPTURE);
    			$offset2=$matches2[0][1];
    			$j=$offset2+3;
    			while(($imgstring[$j]!='"')&&($imgstring[$j]!="\'")) $j++;
    			$j++;
    			$url='';
    			while(($imgstring[$j]!='"')&&($imgstring[$j]!="\'")){
    				$url.=$imgstring[$j];
    				$j++;
    			}
    			error_log("[str]:$url");
    			$images[]=$url;
			
		}
		foreach($images as $index=>$img){
			if($img[0]!='h'){
				$ar=explode('/',$img);
				$newimg=$ar[count($ar)-1];
				$html=str_replace($img,$newimg,$html);	
			}	
			
		}
		$images[]=$html;
		return $images;
	}
}
?>